package com.lovo.roomProject.classManager.dao.impl;

import com.lovo.roomProject.classManager.dao.ClassDAO;
import com.lovo.roomProject.dao.BaseDAO;
import com.lovo.roomProject.pojo.ClaszDO;

import java.sql.SQLException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

public class ClassDAOImpl extends BaseDAO implements ClassDAO {

    @Override
    public List listClass() {
        this.getConnection();
        String sql ="select * from t_class";
        List list =new ArrayList();
        try {
            statement=con.prepareStatement(sql);
            rs=statement.executeQuery();
            while (rs.next()){
                ClaszDO claszDO =new ClaszDO();
                claszDO.setId(rs.getInt("c_id"));
                claszDO.setName(rs.getString("c_name"));
                claszDO.setTeacher(rs.getString("c_teacher"));
                claszDO.setDate(LocalDate.parse(rs.getString("c_create_date")));

                list.add(claszDO);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            close(con,statement,rs);
        }


        return list;
    }
}
